import 'package:flutter/cupertino.dart';
import 'package:kq_flutter_core_widget/utils/ex/string_ex.dart';
import 'package:kq_flutter_tv_widgets/widgets/input/input_number_view.dart';
import 'package:kq_flutter_tv_widgets/widgets/input/input_opt_type.dart';
import 'package:kq_flutter_tv_widgets/widgets/text/kq_text.dart';

/// 数字键盘兼容KqText控件，方便使用
class InputNumberViewFitKqTextFieldUtil {
  static bind(InputNumberViewFitKqTextFieldController fitController,
      InputNumberViewController inputController) {
    inputController.onOpt = (InputOptType type, int? input) {
      if (type == InputOptType.number) {
        int num = int.tryParse(fitController.textController?.text ?? "0") ?? 0;
        if (num == 0) {
          fitController.textController?.text = "$input";
        } else {
          fitController.textController?.text =
              "${fitController.textController?.text}$input";
        }
      } else if (type == InputOptType.clear) {
        fitController.textController?.text = "";
      } else if (type == InputOptType.delete) {
        String? text = fitController.textController?.text;
        if (text.isNotNullOrEmpty) {
          text = text!.substring(0, text.length - 1);
          fitController.textController?.text = text;
        }
      }
    };
  }
}

class InputNumberViewFitKqTextFieldController {
  KqTextController? textController;
}
